local config = {
    -- watchchpoint config
    watchpoint  = false,
    -- detect config
    detect      = false,
    -- trace config
    vtrace      = false,
    itrace      = false,
    -- difftest config
    difftest    = false,
    -- device config
    clint       = true,
    display     = true,
    keyboard    = true,
}

add_rules("mode.debug", "mode.release", "mode.check")
add_requires("verilator")
target("Vtop")
    add_rules("verilator.binary")
    set_toolchains("@verilator")
    add_includedirs("csrc/include")
    add_files("vsrc/*.sv")
    add_files("vsrc/*/*.sv")
    add_files("csrc/*/*.cpp")
    add_files("csrc/*.cpp")
    add_links("readline", "SDL2")
    -- add defines
    add_defines("CONFIG_ISA64")
    if config.watchpoint    then add_defines("CONFIG_WATCHPOINT")   end
    if config.detect        then add_defines("CONFIG_DETECT")       end
    if config.itrace        then add_defines("CONFIG_ITRACE")       end
    if config.vtrace        then add_defines("CONFIG_VTRACE")       end
    if config.difftest      then add_defines("CONFIG_DIFFTEST")     end
    if config.clint         then add_defines("CONFIG_CLINT")        end
    if config.display       then add_defines("CONFIG_DISPLAY")      end
    if config.keyboard      then add_defines("CONFIG_KEYBOARD")     end
    -- set top module
    add_values("verilator.flags", "--top-module", "top")
    -- set trace
    if config.vtrace then add_values("verilator.flags", "--trace") end
    -- set SV include directory
    add_values("verilator.flags", "-y", "vsrc") 
    -- set other flags
    add_values("verilator.flags", "--noassert")
    add_values("verilator.flags", "-O3")
    -- set runargs
    set_runargs("--ref=/home/zhengqc/Project/ysyx-workbench/npc/spike-diff/build/spike-ref-so", 
                "--img=/home/zhengqc/Project/ysyx-workbench/nanos-lite/build/nanos-lite-riscv64-npc.bin",
                -- "--img=/home/zhengqc/Project/ysyx-workbench/npc/test/amtest-intr-riscv64-nemu.bin",
                -- "--img=/home/zhengqc/Project/ysyx-workbench/npc/test/add-longlong-riscv64-nemu.bin",
                "--log=$(projectdir)/build/log")
    -- 编译之后执行
    after_build(function (target)
        os.exec("make build -f git_commit.mk")
    end)
    -- 运行之前执行
    before_run(function (target)
        os.exec("make run -f git_commit.mk")
    end)
